from itsdangerous import TimedJSONWebSignatureSerializer as Serializer

SECRET_KEY = '51)fj#mnm%-ctk6+$eah%5=rv(rsl(2k5ntivjgt&7f3=%a7j+'
TOKEN_TIME = 24 * 60 * 60


def generate_key(username):
    serializer = Serializer(SECRET_KEY, TOKEN_TIME)
    info = {"username": username}
    mi_info = serializer.dumps(info)
    mi_info = mi_info.decode()
    return mi_info


def de_ser(mi_info):
    try:
        serializer = Serializer(SECRET_KEY, TOKEN_TIME)
        yuan_info = serializer.loads(mi_info)
    except:
        yuan_info = {}
    return yuan_info

a = generate_key("admin")
b = de_ser(a)

